package com.cungmua.app.activity;

import android.os.Bundle;

import com.cungmua.app.handler.GetCategoryDealHandler;
import com.cungmua.app.model.Category;
import com.cungmua.app.model.User;
import com.cungmua.app.model.request.GetCategoryDealRequest;
import com.cungmua.app.model.request.LoginRequest;
import com.cungmua.app.model.response.GetCategoryDealResponse;
import com.cungmua.app.task.GetCategoryDealTask;

/**
 * Created by kelvin.nguyen on 6/17/14.
 */
public class CategoryActivity extends DealListActivity implements GetCategoryDealHandler{
    private int categoryId;
    private Category category;
    private GetCategoryDealRequest request;
    private GetCategoryDealTask task;

    public static final int HOTEST = 0;
    public static final int NEWEST = 1;

    private int dealType;
    private String title = "";



    @Override
    public void updateView() {
       // getActionBar().setTitle(title);


        request = new GetCategoryDealRequest(getDeviceId(), getToken());
        if (dealType == HOTEST) {
            request.setSortType(1);
        } else if (dealType == NEWEST) {
            request.setSortType(2);
        }
if(category!=null) {
    request.setCityId(getCurrentCity().getId());
    request.setUserId(getCurrentUser().getId());
    request.setCateId(category.getId());
    request.setParentId(category.getParentId());
    request.setPageIndex(currentPage);
    GetCategoryDealTask task = new GetCategoryDealTask(this, this);
    task.execute(request);
}
    }

    @Override
    public void setDealType(int dealType) {
        this.dealType = dealType;
        request.setSortType(dealType);
    }

    @Override
    public void loadControls(Bundle savedInstanceState) {
        dealType = HOTEST;

        super.loadControls(savedInstanceState);
        Bundle b = getIntent().getExtras();
        categoryId = b.getInt(IK_CATEGORY_ID);
        category = getCategoryById(categoryId);

        title = b.getString("TITLE");
        title=title.equalsIgnoreCase("Tất cả")?category.getName():title;
        setTitleDeal(title);

//        getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
//        ActionBar.Tab tab = getActionBar().newTab().setText(R.string.hotest).setTabListener(this);
//        getActionBar().addTab(tab);
//
//
//        tab = getActionBar().newTab().setText(R.string.newest).setTabListener(this);
//        getActionBar().addTab(tab);

//        getActionBar().setTitle(title);
    }

    @Override
    public void onCategoryDeal(GetCategoryDealResponse response) {
        onListDealData(response);
    }

    @Override
    public void setLastLoginRequest(LoginRequest request) {

    }

    @Override
    public void setCurrentUser(User data) {

    }
}
